﻿using System;
using System.Collections.Generic;
using System.Text;
using DBUtility;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;
namespace ATSDAL
{
    public class TCalibration : BaseRepository_DT<TCalRecordInfo>, ITCalibration
    {
         private const String PRAM_Cali_InstrumentID = "@InstrumentID";
         private const String PRAM_Cali_RecordTime = "@RecordTime";
         private const String PRAM_Cali_UserID = "@UserID";
         private const String PRAM_Cali_UserID2 = "@UserID2";
         private const String PRAM_Cali_PCIP = "@PCIP";
         private const String PRAM_Cali_ValueType = "@ValueType";
         private const String PRAM_Cali_IsPass = "@IsPass";



         public IList<TCalRecordInfo> LoadEntities()
         {
             return null;
         }

         public TCalRecordInfo LoadEntity<T1>(T1 Id)
         {
             return null;
         }


        public IList<TCalRecordInfo> GetCalibrationsByIID(String InstrumentID)
        {
            SqlParameter parm =new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 50);
            parm.Value = InstrumentID;
            return ExcuteSqlToGetEntities("CalRecord_select_SN", parm);
             
        }

        
        public IList<TCalRecordInfo> GetCalibrationsbyDT(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] testParms = GetDTParameters();
         
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            return ExcuteSqlToGetEntities("CalRecord_select_DT", testParms);
        
        }






        public TCalRecordInfo GetCalibrationByIID(String InstrumentID)
        {

            SqlParameter parm = new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 50);
            parm.Value = InstrumentID;
            return ExcuteSqlToGetEntity("TTest_select_SN", parm);

        }

        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TCalRecordInfo GetEntityRecord(SqlDataReader rdr)
        {
            TCalRecordInfo pro = new TCalRecordInfo
            {
                InstrumentID = rdr.GetValue(0).ToString(),
                RecordTime = rdr.GetDateTime(1),
                UserID = rdr.GetValue(2).ToString(),
                UserID2 = rdr.GetValue(3).ToString(),
                PCIP = rdr .GetValue(4).ToString(),
                ValueType = rdr.GetValue(5).ToString(),
                IsPass = rdr.GetValue(6).ToString ()
            };
            return pro;
        }

        public override TCalRecordInfo GetEntityRecord()
        {
            TCalRecordInfo pro = new TCalRecordInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TTest_Insert1";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

       

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PRAM_Cali_InstrumentID, SqlDbType.NVarChar, 200),
                    new SqlParameter(PRAM_Cali_RecordTime, SqlDbType.DateTime),
                    new SqlParameter(PRAM_Cali_UserID, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_UserID2, SqlDbType.NVarChar, 50),
                    new SqlParameter(PRAM_Cali_PCIP, SqlDbType.NVarChar, 20),
                    new SqlParameter(PRAM_Cali_ValueType, SqlDbType.NVarChar, 50),
					new SqlParameter(PRAM_Cali_IsPass, SqlDbType.NVarChar, 50),
                    
                };
            return parms;
        }

        public override void SetParameters(TCalRecordInfo tpti, params SqlParameter[] Parms)
        {
            Parms[0].Value = tpti.InstrumentID;
            Parms[1].Value = tpti.RecordTime;
            Parms[2].Value = tpti.UserID;
            Parms[3].Value = tpti.UserID;
            Parms[4].Value = tpti.UserID2;
            Parms[5].Value = tpti.PCIP;
            Parms[6].Value = tpti.ValueType;
            Parms[7].Value = tpti.IsPass;
           
        }



         

    }
}
